package com.monkeysonnet.b2dFluent;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.joints.RopeJoint;
import com.badlogic.gdx.physics.box2d.joints.RopeJointDef;

public class RopeJointFactory extends JointFactory<RopeJointFactory>
{
	private static final RopeJointDef _initialDef = new RopeJointDef();
	
	private RopeJointDef _def;
	
	public RopeJointFactory()
	{
		this(false);
	}
	
	RopeJointFactory(boolean managed)
	{
		super(managed);
		_def = new RopeJointDef();
		setDef(_def);
	}
	
	public RopeJointFactory localAnchorA (Vector2 v)
	{
		_def.localAnchorA.set(v);
		return this;
	}
	
	public RopeJointFactory localAnchorA (float x, float y)
	{
		_def.localAnchorA.set(x, y);
		return this;
	}
	
	public RopeJointFactory localAnchorB (Vector2 v)
	{
		_def.localAnchorB.set(v);
		return this;
	}
	
	public RopeJointFactory localAnchorB (float x, float y)
	{
		_def.localAnchorB.set(x, y);
		return this;
	}
	
	public RopeJointFactory maxLength(float l)
	{
		_def.maxLength = l;
		return this;
	}
	
	public RopeJoint create(World w)
	{
		return (RopeJoint)w.createJoint(_def);
	}
	
	void clear()
	{
		super.clear(_initialDef);
		_def.localAnchorA.set(_initialDef.localAnchorA);
		_def.localAnchorB.set(_initialDef.localAnchorB);
		_def.maxLength = _initialDef.maxLength;
	}

	@Override
	public void free()
	{
		B2d.free(this);
	}
}
